const path = require('path')
const resolve = dir => {
	return path.join(__dirname, dir)
}

const name = 'Mini Hide' // page title

// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following method:
// port = 8080 npm run dev OR npm run dev --port = 8080
const port = process.env.port || process.env.npm_config_port || 80 // dev port

module.exports = {
	/**
	 * You will need to set publicPath if you plan to deploy your site under a sub path,
	 * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
	 * then publicPath should be set to "/bar/".
	 * In most cases please use '/' !!!
	 * Detail: https://cli.vuejs.org/config/#publicpath
	 */
	publicPath: '/',
	outputDir: 'dist',
	assetsDir: 'static',
	// 项目为了兼容性，会编译成es5的代码，但是node_module中的依赖包，默认都不编译。所以需要使用transpileDependencies这个对象来手动编译
	// transpileDependencies: ['highcharts'],
	chainWebpack: config => {
		config.resolve.symlinks(true); // 修复热更新失效
		// 添加别名
		config.resolve.alias.set('_c', resolve('src/components')) // key,value自行定义，比如.set('@@', resolve('src/components'))
	},
	lintOnSave: false,
	productionSourceMap: false,
	devServer: {
		port: port,
		open: true, // 配置自动启动浏览器
		hotOnly: true, // 热更新
		overlay: { // 让浏览器 overlay 同时显示警告和错误
			warnings: false,
			errors: true
		},
		// 配置多个跨域
		proxy: {
			'/dev-api': {
				target: 'http://127.0.0.1:8080', // 后端提供的真实接口
				changeOrigin: true,
				// ws: true, // websocket支持
				secure: false,
				pathRewrite: {
					// 如果接口中是没有api的，那就直接置空，'^/api': ''，
					// 如果接口中有api，那就得写成{'^/api':'/api'}
					'^/dev-api': ''
				}
			}
		}
	},
	configureWebpack: {
		// provide the app's title in webpack's name field, so that
		// it can be accessed in index.html to inject the correct title.
		name: name,
		resolve: {
			alias: {
				'@': resolve('src')
			}
		}
	}
}